package app.itgungnir.compose.wan.utils

import android.util.Base64
import java.util.*

/**
 * 字符串加密
 */
fun String?.encode(): String = try {
    Base64.encodeToString(this?.toByteArray(), Base64.NO_WRAP)
} catch (e: Exception) {
    ""
}

/**
 * 字符串解密
 */
fun String?.decode(): String = try {
    String(Base64.decode(this, Base64.NO_WRAP))
} catch (e: Exception) {
    ""
}

/**
 * 时间戳转字符串（yyyy-MM-dd）
 */
fun Long?.toDateString(): String? = this?.run { Calendar.getInstance().apply { timeInMillis = this@run } }?.run {
    "${get(Calendar.YEAR)}-${get(Calendar.MONTH) + 1}-${get(Calendar.DAY_OF_MONTH)}"
}
